3
3
.
.
2
2
.
.
4
4
B
B
u
u
t
t
t
t
o
o
n
n
A
A
c
c
t
t
i
i
o
o
n
n
I
I
n
n
f
f
o
o
This tutorial shows how to execute an Action (that prints to Debug Area) when Button is pressed.
This can be done only through the Code.
Code can be tested using Simulator or Automatic Preview (if you activate its Play Button).
Open Debag Area to see printed message.
Bind Button to Action
ContentView.swift
struct ContentView: View {
var body: some View {
VStack {
Button(action: {
print("Button was pressed")
}) {
Text("Button")
}
}
}
}